package com.tl.web.controller.api;

import java.util.List;
import java.util.Map;

import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.web.bind.annotation.GetMapping;
import org.springframework.web.bind.annotation.PostMapping;
import org.springframework.web.bind.annotation.RequestBody;
import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.bind.annotation.RestController;

import com.tl.app.domain.AppClerk;
import com.tl.app.domain.AppClerkComment;
import com.tl.app.service.IAppClerkCommentService;
import com.tl.app.service.IAppClerkService;
import com.tl.app.service.IAppGiftUserService;
import com.tl.common.annotation.Log;
import com.tl.common.core.controller.BaseController;
import com.tl.common.core.domain.AjaxResult;
import com.tl.common.core.page.TableDataInfo;
import com.tl.common.enums.BusinessType;



@RestController
@RequestMapping("/api/clerk")
public class ApiClerkController extends BaseController{
	
	
	@Autowired
	private IAppClerkService appClerkService;
	
	@Autowired
	private IAppClerkCommentService appClerkCommentService;
	
	@Autowired
	private IAppGiftUserService appGiftUserService;
	

    /**
     * 获取男神/女神榜
     */
    @GetMapping("/getListTop")
    public AjaxResult getListTop(AppClerk appClerk)
    {
        List<AppClerk> list = appClerkService.selectAppClerkTop(appClerk);
        return AjaxResult.success(list);
    }
	
    
    /**
     * 查询店员列表
     */
    @GetMapping("/list")
    public TableDataInfo list(AppClerk appClerk)
    {
        startPage();
        appClerk.setStatus("ytg");
        List<AppClerk> list = appClerkService.selectAppClerkList(appClerk);
        return getDataTable(list);
    }
    
    /**
     * 查询当前登录店员信息
     */
    @GetMapping("/getUserClerk")
    public AjaxResult getUserClerk(AppClerk appClerk){
        AppClerk ac = appClerkService.selectAppClerkByUserId(getUserId());
        return AjaxResult.success(ac);
    }
    
    /**
     * 新增店员
     */
    @Log(title = "店员", businessType = BusinessType.INSERT)
    @PostMapping("/add")
    public AjaxResult add(@RequestBody AppClerk appClerk)
    {
    	appClerk.setUserId(getUserId());
    	appClerk.setStatus("dsh");
        return toAjax(appClerkService.insertAppClerk(appClerk));
    }
    
    /**
     * 修改店员
     */
    @Log(title = "店员", businessType = BusinessType.UPDATE)
    @PostMapping("/edit")
    public AjaxResult edit(@RequestBody AppClerk appClerk)
    {
        return toAjax(appClerkService.updateAppClerk(appClerk));
    }
    
    
    /**
     * 根据店员id查询详情
     */
    @GetMapping("/getClerkInfo")
    public AjaxResult getClerkInfo(AppClerk appClerk){
        AppClerk ac = appClerkService.selectAppClerkByUserId(appClerk.getUserId());
        return AjaxResult.success(ac);
    }
    
    /**
     * 获取店员评论
     */
    @GetMapping("/getClerkCommentList")
    public TableDataInfo getClerkCommentList(AppClerkComment appClerkComment){
    	List<AppClerkComment> list = appClerkCommentService.selectAppClerkCommentList(appClerkComment);
    	return getDataTable(list);
    }
    
    
    /**
     * 获取店员礼物墙
     */
    @GetMapping("/getClerkGift")
    public AjaxResult getClerkGift(AppClerk appClerk){
    	Map<String, Object> map = appGiftUserService.selectAppGiftUserByClerkInfo(appClerk.getUserId(),"clerk");
    	return AjaxResult.success(map);
    }
    
}
